'use strict';
const nodemailer = require('nodemailer');

// 创建发送邮件的对象
let transporter = nodemailer.createTransport({
  host: 'smtp.qq.com', // 发送方 邮箱
  port: 465, //端口号
  secure: true, // true for 465, false for other ports
  auth: {
    /*  下面两行自己写  */
    user: '499565606@qq.com', // 发送方邮箱
    pass: 'xwce888soudzkdg888cahf', // smtp 验证码
  },
});
function send(mail, code) {
  // 邮件信息
  let mailobj = {
    from: `${transporter.options.auth.user}`, // sender address
    to: mail, // list of receivers
    subject: 'Hello ✔', // Subject line
    text: `您的验证码是${code}, 有效期五分钟`, // 必须是字符串，数字都会报错
  };
  return new Promise((resolve, reject) => {
    // 发送邮件
    transporter.sendMail(mailobj, (err, data) => {
      if(err){
        reject();
      }else{
        resolve();
      }
    });
  });
}
module.exports = { send };
